package com.feiyumall.account.controller;

import com.feiyu.common.utils.R;
import com.feiyumall.account.dto.loginDto;
import com.feiyumall.account.dto.registerDto;
import com.feiyumall.account.entity.redis.accountInfoEntity;
import com.feiyumall.account.service.loginService;
import com.feiyumall.account.service.tokenService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author: Doate
 * @Date: Created in 2021/4/10 14:23
 * @Description:
 */

@RestController
public class LoginController {

    @Resource
    loginService loginService;

    @Resource
    tokenService tokenService;

    @PostMapping("/openFeiyu/login")
    public R logining(HttpServletResponse response, @RequestBody loginDto dto) {

        return loginService.logining(response,dto);
    }

    @PostMapping("/check")
    public accountInfoEntity loginCheck(@RequestBody String token) {

        return loginService.loginCheck(token);
    }

    @PostMapping("/openFeiyu/register")
    public R register(@RequestBody registerDto dto) {

        return loginService.register(dto);
    }

    @PostMapping("/update")
    public R updateUser(@RequestBody registerDto dto ,@RequestHeader("userId") int userId) {
//        int id = Integer.valueOf(userId);
        return loginService.updateUser(dto,userId);
    }

    @PostMapping("quit")
    public R quit(@RequestHeader("token") String token) {

        tokenService.quit(token);
        return R.ok();
    }





    @PostMapping("/test")
    public R test(@RequestHeader("userId") String userId) {
        System.out.println(Integer.valueOf(userId));
        Map<String,Object> map = new HashMap<>();
        map.put("userId",1);
        map.put("userPower","123321");

        return R.ok().put("data",map);
    }


}
